package com.xialuo.handler;

import com.xialuo.exception.MyException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.http.HttpRequest;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@ControllerAdvice
public class MyExceptionHandler  {


    @ExceptionHandler({MyException.class})
    @ResponseBody
    public Map<String,String> requestNotReadable(Exception e) {

        Map<String,String> result =new HashMap<>();
        result.put("msg",e.getMessage());
        return result;
    }
    @ExceptionHandler({AuthorizationException.class})
    public String requestNotAuthorization(AuthorizationException e) {

        System.out.println("进入AuthorizationException异常");
        return "redirect:/notRole";
    }


}
